<template>
    <el-form ref="form" :model="form" label-width="40px">
      <el-form-item label="标题">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="form.data" type="textarea"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="editData">确定</el-button>
        <el-button @click="Esc">取消</el-button>
      </el-form-item>
    </el-form>
  </template>

<script>
    import axios from 'axios'
    import message from '../modular/message.js'
    export default {
        data() {
            return {
                form: {

                },
            }
        },
        methods: {
            editData() {
                let path = `/article/${this.$route.params.id}/edit`;
                console.log(this.$route.params.id, 'id')
                axios.put(path, this.form).then(res => {
                    if (res.data.Code == 200) {
                        message(res.data.message, 'success')
                    } else {
                        message(res.data.message, 'error')
                    }
                    this.$router.push(`/article/list`)
                })
            },
            Esc() {
                this.$router.push(`/article/list`)
            }
        },
        created() {
            axios.get(`/article/getDeitData/${this.$route.params.id}`).then(res => {
                this.form = res.data.body[0];
            })
        }
    }
</script>